<?php


namespace paySdk\functions\postar\lib\Request\Body\Order;


class WechatOrder extends Order
{
    /**
     * 微信支付必须参数
     */
    public $wechat_available_parameters = ["open_id", "wechat_app_id", "wechat_access_code", "wechat_device_no",
        "wechat_order_timeout"];

    public $auto_init_parameters = ["pay_way" => 1];

    /**
     * wechatOrder constructor.
     * @param array $parameters
     * @throws \Exception
     */
    public function __construct($parameters = []) {
        $this->__set("timestamp", time());
        $this->available_parameters = array_merge($this->available_parameters, $this->wechat_available_parameters);

        $auto_init_parameters = $this->auto_init_parameters;
        array_walk($auto_init_parameters, function ($value, $ele) {
            $this->__set($ele, $value);
        });

        if (! empty($parameters)) {
            array_walk($parameters, function ($item, $key) {
                $this->__set($key, $item);
            });
            $this->chkParam();
        }
    }
}